﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using SuperStarProject.Models;
using System.Data.SqlClient;

namespace SuperStarProject.DAO
{
    public class DaiLyDAO
    {
        public static List<DaiLyModel> ShowAll()
        {
            SqlConnection db = DataProvider.DBconnection();
            SqlDataReader rdr = DataProvider.RunStoredProc_Read("sp_select_DaiLy", db);
            return Convert(rdr);
        }
        static List<DaiLyModel> Convert(SqlDataReader rdr)
        {
            List<DaiLyModel> lstItem = new List<DaiLyModel>();
            while (rdr.Read())
            {
                DaiLyModel item = new DaiLyModel();
                item.MaDaiLy = (string)rdr["MaDaiLy"];
                item.TenDaiLy = (string)rdr["TenDaiLy"];
                item.Password = (string)rdr["Password"];
                lstItem.Add(item);
            }
            return lstItem;
        }
        public static bool ValidateUser(string username, string password)
        {
            if ((ValidateDaiLy(username, password)) || (ValidateNhanVien(username, password)))
            {
                return true;
            }
            else
                return false;
        }
        public static bool ValidateDaiLy(string username, string password)
        {
            ProductModel prod = new ProductModel();


            SqlConnection db = DataProvider.DBconnection();

            List<SqlParameter> lstParameter = new List<SqlParameter>();
            lstParameter.Add(new SqlParameter("@madaily", (object)username));
            lstParameter.Add(new SqlParameter("@pass", (object)password));

            SqlDataReader rdr = DataProvider.RunStoredProcParams_Read("select_daily_all", db, lstParameter);
            if (rdr.HasRows)
                return true;
            return false;
        }
        public static bool ValidateNhanVien(string username, string password)
        {
            ProductModel prod = new ProductModel();


            SqlConnection db = DataProvider.DBconnection();

            List<SqlParameter> lstParameter = new List<SqlParameter>();
            lstParameter.Add(new SqlParameter("@manv", (object)username));
            lstParameter.Add(new SqlParameter("@pass", (object)password));

            SqlDataReader rdr = DataProvider.RunStoredProcParams_Read("sp_select_NhanVien_By_UserNamePassWord", db, lstParameter);
            if (rdr.HasRows)
                return true;
            return false;
        }

    }
}
